using System;
using System.Data;
//using PCS's namespace
using PCSComProduct.STDCost.DS;
using PCSComUtils.DataContext;
using System.Collections.Generic;
using System.Transactions;
using PCSComUtils.DataAccess;
using System.Linq;

namespace PCSComProduct.STDCost.BO
{
    public class ItemStandardCostBO //: IItemStandardCostBO
    {
        private const string THIS = "PCSComProduct.STDCost.BO.ItemStandardCostBO";
        public ItemStandardCostBO()
        {
            //
            // TODO: Add constructor logic here
            //
        }


        //[AutoComplete(true)]
        public void Add(object pobjDetail)
        {
            CST_STDItemCostDS dsItemCost = new CST_STDItemCostDS();
            dsItemCost.Add(pobjDetail);
        }

        //[AutoComplete(true)]
        public void Delete(object pobjDetail)
        {

        }

        //[AutoComplete(true)]
        public void Delete(int pintItemCostID)
        {
            CST_STDItemCostDS dsItemCost = new CST_STDItemCostDS();
            dsItemCost.Delete(pintItemCostID);
        }

        //[AutoComplete(true)]
        public void DeleteByProduct(int pintProductID)
        {
            CST_STDItemCostDS dsItemCost = new CST_STDItemCostDS();
            dsItemCost.DeleteByProduct(pintProductID);
        }

        //[AutoComplete(true)]
        public object GetObjectVO(int pintID, string pstrClass)
        {
            return null;
        }

        //[AutoComplete(true)]
        public object GetObjectVO(int pintID)
        {
            CST_STDItemCostDS dsItemCost = new CST_STDItemCostDS();
            return dsItemCost.GetObjectVO(pintID);
        }

        //[AutoComplete(true)]
        public DataTable GetProductItemInfo(int pintProductID)
        {
            CST_STDItemCostDS dsItemCost = new CST_STDItemCostDS();
            return dsItemCost.GetProductItemInfo(pintProductID);
        }

        //[AutoComplete(true)]
        public DataTable GetItemCostDetail(int pintProductID)
        {
            CST_STDItemCostDS dsItemCost = new CST_STDItemCostDS();
            return dsItemCost.GetItemCostDetail(pintProductID);
        }

        //[AutoComplete(true)]
        public void Update(object pobjDetail)
        {
            CST_STDItemCostDS dsItemCost = new CST_STDItemCostDS();
            dsItemCost.Update(pobjDetail);
        }

        //[AutoComplete(true)]
        public void UpdateDataSet(DataSet dstData)
        {
            CST_STDItemCostDS dsItemCost = new CST_STDItemCostDS();
            dsItemCost.UpdateDataSet(dstData);
        }
        public void UpdateItemCost(List<CST_STDItemCost> list, int iProductID)
        {
            using (var trans = new TransactionScope())
            {
                using (var db = new PCSDataContext(Utils.Instance.ConnectionString))
                {
                    try
                    {
                        var listDel = db.CST_STDItemCosts.Where(e => e.ProductID == iProductID);
                        if (listDel.Count() > 0)
                        {
                            db.CST_STDItemCosts.DeleteAllOnSubmit(listDel); db.SubmitChanges();
                        }
                        db.CST_STDItemCosts.InsertAllOnSubmit(list);
                        db.SubmitChanges();
                    }
                    catch (Exception ex)
                    { throw ex; }
                    finally
                    {
                        trans.Complete();
                    }
                }
            }

        }
    }
}
